package com.cjzuji.rental.dao.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cjzuji.rental.dao.AiZuJiContractDao;
import com.cjzuji.rental.mapper.OrderContractMapper;
import com.cjzuji.rental.pojo.OrderContract;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class AiZuJiContractDaoImpl implements AiZuJiContractDao {
    private static final Logger logger = LoggerFactory.getLogger(AiZuJiContractDaoImpl.class);
    @Autowired
    OrderContractMapper orderContractMapper;

    @Override
    @Transactional
    public  void save(List<Map<String,Object>> data, Long orderID) {
        List<OrderContract>  contractList = new ArrayList<>();
        for (Map<String, Object> item : data){
            OrderContract orderContract = OrderContract.builder()
                    .orderId(orderID)
                    .contractNo(item.get("rentRecordNo").toString())
                    .title(item.get("contractName").toString())
                    .url(item.get("sealAgreementUrl").toString())
                    .addTime("")
                    .createTime(new Date())
                    .updateTime(new Date())
                    .build();
            contractList.add(orderContract);
        }
        try {
            orderContractMapper.insertBatchSomeColumn(contractList);
        }catch (Exception e){
            logger.info("订单合同添加错误" + e.getMessage());
            throw e;
        }
    }
}
